﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;

namespace LuaLanguageExtension.Parsing
{
    /// <summary>
    /// Interface for TokenStreamProviderBroker
    /// </summary>
    internal interface IObjectModelProviderBroker
    {
        ObjectModelProvider GetProvider(ITextBuffer buffer);
        bool IsLua(ITextBuffer buffer);
    }

    [Export(typeof(IObjectModelProviderBroker))]
    internal class ObjectModelProviderBroker : IObjectModelProviderBroker
    {
        public bool IsLua(ITextBuffer buffer)
        {
            switch (buffer.ContentType.TypeName)
            {
                case Constants.LuaLanguageExtension: return true;
                default: return false;
            }
        }

        public ObjectModelProvider GetProvider(ITextBuffer buffer)
        {
            ObjectModelProvider provider;
            if (!buffer.Properties.TryGetProperty(typeof(ObjectModelProvider), out provider))
            {
                buffer.Properties.AddProperty(typeof(ObjectModelProvider), provider = new ObjectModelProvider(buffer));
            }
            return provider;
        }

    }
}
